from PyQt5.QtCore import Qt, QCoreApplication
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QLabel, QWidget, QVBoxLayout

from ui.game_over import Ui_Dialog


class GameOverDialog(QDialog):
    def __init__(self, is_good_ending: bool, parent=None):
        super().__init__(parent)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.ending = is_good_ending


        self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)
        self.setFixedSize(300, 200)  # 设置对话框大小
        # 修改按钮文本
        self.ui.buttonBox.button(QDialogButtonBox.Ok).setText("返回主菜单")
        self.ui.buttonBox.button(QDialogButtonBox.Cancel).setText("退出游戏")

        # （可选）重新绑定功能
        self.ui.buttonBox.button(QDialogButtonBox.Ok).clicked.connect(self.handle_return_to_menu)
        self.ui.buttonBox.button(QDialogButtonBox.Cancel).clicked.connect(self.handle_exit_game)

        self.get_ending()

    def handle_return_to_menu(self):
        # print("返回主菜单")
        self.accept()

    def handle_exit_game(self):
        # print("退出游戏")
        self.reject()  # or
        QCoreApplication.quit()

    def get_ending(self):
        if self.ending:
            self.ui.label.setStyleSheet("""
                QLabel {
                  background-image: url(:/image/good_ending.png);
                }
            """)
            text = "你终于把FW干死了"
            self.ui.label.setText(text)
            self.setWindowTitle(text)
        else:
            self.ui.label.setStyleSheet("""
                            QLabel {
                              background-image: url(:/image/bad_ending.png);
                            }
                        """)
            self.setWindowTitle("连FW都没干死，你才是真正的FW")
            self.ui.label.setText("连FW都没干死\n你才是真正的FW")







